package com.jacen.fzxs.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.jacen.fzxs.dao.IRoleDao;
import com.jacen.fzxs.entity.RoleEntity;
import com.jacen.fzxs.util.SqlCondition;
import com.jacen.fzxs.util.Utils;


@Repository
public class RoleDao extends BaseDao<RoleEntity> implements IRoleDao {

	@Override
	public List<RoleEntity> getPage(int start, int size, Map<String, String> params) {
		SqlCondition cond = getPageCondition(params);
		String sql = "SELECT * from t_role where 1=1 %s ";
		sql = String.format(sql, cond.getCondition());
		sql = SqlCondition.pageSql(sql, start, size);
		return executeForList(sql, cond.getParams().toArray());
	}

	@Override
	public int getCount(Map<String, ? extends Object> params) {
		SqlCondition cond = getPageCondition(params);
		String sql = "select count(1) from t_role where 1=1 %s";
		sql = String.format(sql, cond.getCondition());
		return Long.valueOf(executeForLong(sql, cond.getParams().toArray())).intValue();
	}
	
	private SqlCondition getPageCondition(Map<String, ? extends Object> mapParams) {
		SqlCondition cond = new SqlCondition();
		if (Utils.paramIsNotEmpty(mapParams.get("rolename")))
			cond.and().equal("rolename", mapParams.get("rolename"));
		return cond;
	}

}
